/// @tags: CDQ
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long LL;

int const N = 8e4 + 5, mod = 998244353;

struct Node {
  int a, b, c, d, id;
  bool A, B;
  LL val, cnt, f;
  inline bool operator<(Node const &rhs) const {
    if (a != rhs.a) return a < rhs.a;
    if (b != rhs.b) return b < rhs.b;
    if (c != rhs.c) return c < rhs.c;
    return d < rhs.d;
  }
  inline bool operator==(Node const &rhs) const {
    return a == rhs.a && b == rhs.b && c == rhs.c && d == rhs.d;
  }
} x[N], t1[N], t2[N];

int n, m, hash[N];

namespace BIT {

LL cnt[N], f[N];

inline int lowbit(int x) { return x & -x; }

inline void modify(int x, LL v, LL sum) {
  for (; x <= n; x += lowbit(x)) {
    if (v > f[x]) {
      f[x] = v;
      cnt[x] = sum;
    } else if (v == f[x]) {
      cnt[x] += sum;
      cnt[x] %= mod;
    }
  }
}

inline void query(int x, LL &ff, LL &sum, LL val) {
  for (; x > 0; x -= lowbit(x)) {
    if (f[x] + val > ff) {
      ff = f[x] + val;
      sum = cnt[x];
    } else if (f[x] + val == ff) {
      sum += cnt[x];
      sum %= mod;
    }
  }
}

inline void del(int x) {
  for (; x <= n; x += lowbit(x)) {
    cnt[x] = f[x] = 0;
  }
}

}  // namespace BIT

inline bool cmp2(const Node &x, const Node &y) {
  if (x.b != y.b) return x.b < y.b;
  if (x.c != y.c) return x.c < y.c;
  if (x.d != y.d) return x.d < y.d;
  return x.a < y.a;
}

inline bool cmp3(const Node &x, const Node &y) {
  if (x.c != y.c) return x.c < y.c;
  if (x.d != y.d) return x.d < y.d;
  if (x.a != y.a) return x.a < y.a;
  return x.b < y.b;
}

void CDQ2(int l, int r) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  CDQ2(l, mid);
  for (int i = l; i <= r; ++i) {
    t1[i].B = (i > mid);
    t2[i] = t1[i];
    t2[i].id = i;
  }
  std::sort(t2 + l, t2 + r + 1, cmp3);
  for (int i = l; i <= r; ++i) {
    if (t2[i].A && t2[i].B) {
      BIT::query(t2[i].d, t2[i].f, t2[i].cnt, t2[i].val);
      t1[t2[i].id].f = t2[i].f;
      t1[t2[i].id].cnt = t2[i].cnt;
    }
    if (!t2[i].A && !t2[i].B) {
      BIT::modify(t2[i].d, t2[i].f, t2[i].cnt);
    }
  }
  for (int i = l; i <= mid; ++i) {
    if (!t1[i].A) {
      BIT::del(t1[i].d);
    }
  }
  CDQ2(mid + 1, r);
}

void CDQ1(int l, int r) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  CDQ1(l, mid);
  for (int i = l; i <= r; ++i) {
    x[i].A = (i > mid);
    t1[i] = x[i];
    t1[i].id = i;
  }
  std::sort(t1 + l, t1 + r + 1, cmp2);
  CDQ2(l, r);
  for (int i = l; i <= r; ++i) {
    x[t1[i].id].f = t1[i].f;
    x[t1[i].id].cnt = t1[i].cnt;
  }
  CDQ1(mid + 1, r);
}

inline int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> x[i].a >> x[i].b >> x[i].c >> x[i].d >> x[i].val;
  }
  std::sort(x + 1, x + n + 1);
  int xcnt = 1;
  for (int i = 2; i <= n; ++i) {
    if (x[i] == x[i - 1]) {
      x[xcnt].val += x[i].val;
    } else {
      x[++xcnt] = x[i];
    }
  }
  n = xcnt;
  for (int i = 1; i <= n; ++i) hash[i] = x[i].a;
  std::sort(hash + 1, hash + n + 1);
  xcnt = std::unique(hash + 1, hash + n + 1) - hash - 1;
  for (int i = 1; i <= n; ++i) x[i].a = std::lower_bound(hash + 1, hash + xcnt + 1, x[i].a) - hash;
  for (int i = 1; i <= n; ++i) hash[i] = x[i].b;
  std::sort(hash + 1, hash + n + 1);
  xcnt = std::unique(hash + 1, hash + n + 1) - hash - 1;
  for (int i = 1; i <= n; ++i) x[i].b = std::lower_bound(hash + 1, hash + xcnt + 1, x[i].b) - hash;
  for (int i = 1; i <= n; ++i) hash[i] = x[i].c;
  std::sort(hash + 1, hash + n + 1);
  xcnt = std::unique(hash + 1, hash + n + 1) - hash - 1;
  for (int i = 1; i <= n; ++i) x[i].c = std::lower_bound(hash + 1, hash + xcnt + 1, x[i].c) - hash;
  for (int i = 1; i <= n; ++i) hash[i] = x[i].d;
  std::sort(hash + 1, hash + n + 1);
  xcnt = std::unique(hash + 1, hash + n + 1) - hash - 1;
  for (int i = 1; i <= n; ++i) x[i].d = std::lower_bound(hash + 1, hash + xcnt + 1, x[i].d) - hash;
  for (int i = 1; i <= n; ++i) {
    x[i].f = x[i].val;
    x[i].cnt = 1;
    x[i].id = i;
  }
  CDQ1(1, n);
  LL sum = 0, ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (x[i].f > ans) {
      ans = x[i].f;
      sum = x[i].cnt;
    } else if (x[i].f == ans) {
      if ((sum += x[i].cnt) >= mod) sum -= mod;
    }
  }
  cout << ans << '\n' << sum;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4849 寻找宝藏.in", "r", stdin);
  freopen("P4849 寻找宝藏.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
